// base
import Taro, { Component } from '@tarojs/taro'
import { View, ScrollView, Image } from '@tarojs/components'
// less
import './index.less'
import { navigateTo } from '../../../../crossplatform/apiservice/navigate'
import pagejumplist from '../../../../configuration/pagejumplist.json'
import { getsettlementMethod, getsettlementMethodName } from '../../../../util/pagemethods'
import scaleImageSrc from '../../../../util/pagemethods/scaleImageSrc'
import { avaterOld } from '../../../../configuration/staticimg'
import tool from '../../../../util/tool'

class JobsRecommended extends Component {
  componentWillMount () {
    // onLoad
  }

  componentDidMount () {
    // onready
  }

  componentDidShow () {
    // onshow
  }

  componentDidHide () {
    // onhide
  }

  componentWillUnmount () {
    // onUnload
  }

  delay (time = 0) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve()
      }, time)
    })
  }

  getArea = data => {
    const place = data.workPlace && data.workPlace.length && data.workPlace[0]
    return place ? `${place.city} ${place.area ? `${place.area}` : '不限地点'}` : ''
  }

  godetail = index => {
    const { dataSource } = this.props
    const datasingle = dataSource[index]
    navigateTo({
      url: `${pagejumplist['job-detail'].path}?id=${datasingle.id}&companyId=${datasingle.companyId}`
    })
  }

  render () {
    const dataSource = this.props.dataSource || []
    return (
      <View className="JobsRecommended_id01416">
        <View className="alumntitle">
          <View className="info-title">
            <View className="info-top">为你推荐优质岗位</View>
            <View className="info-main">职位推荐</View>
          </View>
        </View>
        <View className="alumnilist">
          <ScrollView scrollX>
            <View className="alumnilistscrollwrap">
              {dataSource.map((data, index) => {
                return (
                  <View className="single" key={data.name} onClick={this.godetail.bind(this, index)}>
                    <View className="top-view">
                      <Image
                        className="absimg-bg"
                        src={scaleImageSrc(data.companyLogo) || avaterOld}
                      />
                      <View className="top-container">
                        <Image
                          className="absimg"
                          mode="aspectFill"
                          src={scaleImageSrc(data.companyLogo) || avaterOld}
                        />
                        <View className="cpname">{data.companyName}</View>
                      </View>
                    </View>
                    <View className="bottom-view">
                      <View className="jobnamewrap">
                        <View className="jobname">{data.name}</View>
                        {data.type == 0 ? (
                          <Image
                            className="jobnameimg"
                            src="https://imagesize.hrwork.com/sp/files/f0f92fd2-5c5f-4702-88af-2c4bed62db22.png"
                          />
                        ) : (
                          <Image
                            className="jobnameimg"
                            src="https://imagesize.hrwork.com/sp/files/6b18b1a7-0b04-4cea-85a3-0beb34cc0a89.png"
                          />
                        )}
                      </View>
                      <View className="pricewrap">
                        <View className="price">{data.salary}</View>
                        <View className="unit">{getsettlementMethod(data.settlementMethod)}</View>
                      </View>
                      <View className="titlewrap">
                        <View className="jobarea">{data.area}</View>
                        <View className="jobarea">{getsettlementMethodName(data.settlementMethod)}</View>
                      </View>
                    </View>
                  </View>
                )
              })}
            </View>
          </ScrollView>
        </View>
        {/* <WhiteSpace></WhiteSpace> */}
      </View>
    )
  }
}

export default JobsRecommended
